package com.yy.driver.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yy.driver.pojo.Driver;
import com.yy.driver.service.impl.DriverServiceImpl;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 驾驶员信息表(Driver)表控制层
 *
 * @author yan yi
 * @since 2021-11-27 14:54:51
 * @version 1.0
 */
@RestController
@RequestMapping("/driver")
@Api(value = "驾驶员信息表(Driver)管理",tags = "驾驶员信息表(Driver)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class DriverController {
    /**
     * 服务对象
     */
    @Resource
    private DriverServiceImpl driverServiceImpl;

    /**
     * 通过主键查询单条数据
     * @param page  需要查询的页码
     * @param name  模糊查询的内容
     * @return 单条数据
     */
    @RequestMapping(value = "/chaXunFenYe", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",paramType = "query",dataType = "int",required = true,example = "0"),
            @ApiImplicitParam(name = "name",value = "驾驶员姓名",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "sex",value = "驾驶员性别",paramType = "query",dataType = "int",example = "0")
    })
    public Map<String, Object> chaXunFenYe(@RequestParam(name = "page") int page,
                                           @RequestParam(name = "name",required = false) String name,
                                           @RequestParam(name = "sex",required = false) int sex) {
        return this.driverServiceImpl.chaXunFenYe(page, name, sex);
    }
    
    /**
     * 通过主键删除单条数据
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/shanChuById", method = RequestMethod.POST)
    @ApiOperation(value = "根据主键删除一条驾驶员信息的接口",notes = "根据主键删除一条驾驶员信息的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> shanChuById(@RequestParam("id") String id) {
        return this.driverServiceImpl.shanChuById(id);
    }
    
    /**
     * 通过主键更新单条数据
     * @param driver 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/gengXinById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一条驾驶员信息的接口",notes = "通过主键更新一条驾驶员信息的接口",httpMethod = "POST")
    public Map<String, Object> gengXinById(@RequestBody @ApiParam(name = "driver",value = "pojo模型",required = true) Driver driver) {
        return this.driverServiceImpl.gengXinById(driver);
    }
    
    /**
     * 通过一个pojo对象新增单条数据
     * @param driver 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/xinZeng", method = RequestMethod.POST)
    @ApiOperation(value = "根据完整记录新增一条驾驶员信息的接口",notes = "根据完整记录新增一条驾驶员信息的接口",httpMethod = "POST")
    public Map<String, Object> xinZeng(@RequestBody @ApiParam(name = "driver",value = "pojo模型",required = true) Driver driver) {
        return this.driverServiceImpl.xinZeng(driver);
    }

    @PostMapping(value = "/findByPage")
    @ApiOperation(value = "分页查询",notes = "分页查询",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码",paramType = "query",dataType = "int",example = "1"),
            @ApiImplicitParam(name = "pageSize",value = "页面显示条数",paramType = "query",dataType = "int",example = "10"),
            @ApiImplicitParam(name = "name",value = "驾驶员姓名",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "sex",value = "驾驶员性别",paramType = "query",dataType = "Integer")
    })
    public Map<String,Object> findByPage(@RequestParam(value = "pageNum",required = false)int pageNum,
                                         @RequestParam(value = "pageSize",required = false)int pageSize,
                                         @RequestParam(name = "name",required = false) String name,
                                         @RequestParam(name = "sex",required = false) Integer sex){
        return driverServiceImpl.findByPage(pageNum, pageSize,name,sex);
    }

}